package com.hrms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hrms.entity.Admin;
import com.hrms.mapper.AdminMapper;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    public boolean passwordisRight(Admin admin) {
        // 管理员登录
        String admin_id = admin.getAdmin_id();
        String admin_password = admin.getAdmin_password();

        // 根据admin_id和admin_password查询账号密码是否匹配
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("admin_id", admin_id)
                .eq("admin_password", admin_password);
        int count = (int) count(wrapper);

        if(count == 0) return false;
        else return true;
    }

    public boolean accountExist(Admin admin) {
        // 查询账号是否存在
        String admin_id = admin.getAdmin_id();

        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("admin_id", admin_id);
        int count = (int) count(wrapper);

        if(count == 0) return false;
        else return true;
    }
}
